define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'other/mailbox/index' + location.search,
                    // add_url: 'other/mailbox/add',
                    edit_url: 'other/mailbox/edit',
                    // del_url: 'other/mailbox/del',
                    multi_url: 'other/mailbox/multi',
                    // import_url: 'other/mailbox/import',
                    table: 'mailbox',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                fixedColumns: true,
                fixedRightNumber: 1,
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'order_no', title: __('Order_no'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'type', title: __('Type'), searchList: {"chief":__('Type chief'),"lnspection":__('Type lnspection'),"unit":__('Type unit'),"activity":__('Type activity')}, formatter: Table.api.formatter.normal},
                        {field: 'identity_type', title: __('Identity_type'), searchList: {"10":__('Identity_type 10'),"20":__('Identity_type 20')}, formatter: Table.api.formatter.normal},
                        {field: 'propose_type', title: __('Propose_type'), searchList: {"10":__('Propose_type 10'),"20":__('Propose_type 20'),"30":__('Propose_type 30'),"40":__('Propose_type 40'),"50":__('Propose_type 50'),"60":__('Propose_type 60')}, formatter: Table.api.formatter.normal},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'email', title: __('Email'), operate: 'LIKE', table: table, class: 'autocontent', formatter: Table.api.formatter.content},
                        {field: 'is_anonymity', title: __('Is_anonymity'), searchList: {"10":__('Is_anonymity 10'),"20":__('Is_anonymity 20')}, formatter: Table.api.formatter.normal},
                        {field: 'status', title: __('Status'), searchList: {"10":__('Status 10'),"20":__('Status 20')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},

                        {field: 'operate', title: __('Operate'),
                            table: table,
                           // events: Table.api.events.operate,
                            //formatter: Table.api.formatter.operate,
                            formatter:function(value,row,index){  //新起一个

                                console.log(row);
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                if (row.status == 10) {
                                    $(table).data("operate-dragsort",null);//隐藏操作中的移动按钮，
                                    that.table = table;
                                    return Table.api.formatter.operate.call(that, value, row, index);
                                }else{
                                    return '';
                                }
                            },
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
